/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.kcht.np.common.jwt;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kcht.np.constant.UserStatus;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
  * @Description: spring security 认证 User 扩展用户信息
  * @Author:      liuqi
  * @CreateDate:  2020/4/2 1:46
 */
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JwtUser implements UserDetails {

	/**
	 * @Description:   用户唯一ID
	 * @CreateDate:    2020/3/31 11:17
	 */
	private Long uid;

	/**
	 * @Description:   用户登录时，使用的用户名
	 * @CreateDate:    2020/3/31 11:17
	 */
	private String username;

	/**
	 * @Description:   用户登录时，使用的密码
	 * @CreateDate:    2020/3/31 11:17
	 */
	private String password;

	/**
	 * @Description:   用户状态， [ 0.禁用 1.离线 2.在线 ]
	 * @CreateDate:    2020/3/31 11:18
	 */
	private Integer status;

	private Collection<String> authoritiesCol;

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Override
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@JsonIgnore
	@Override
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Collection<String> getAuthoritiesCol() {
		return authoritiesCol;
	}

	public void setAuthoritiesCol(Collection<String> authoritiesCol) {
		this.authoritiesCol = authoritiesCol;
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return null;
	}


	@JsonIgnore
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@JsonIgnore
	@Override
	public boolean isAccountNonLocked() {
		return status != UserStatus.DISABLE;
	}

	@JsonIgnore
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@JsonIgnore
	@Override
	public boolean isEnabled() {
		return true;
	}
}
